//
//  InfoMationCollectionViewCell.m
//  Arts1
//
//  Created by apple on 15/8/28.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "InfoMationCollectionViewCell.h"

#import "AllHeader.h"

@implementation InfoMationCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self creactView];
    }
    return self;
}

/**
 *  创建控件视图
 */
- (void)creactView
{
    _infoMationView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 16, 70)];
    _infoMationView.backgroundColor = [UIColor whiteColor];
    _infoMationView.layer.cornerRadius = 5;
    
    //加阴影
    [UIView viewShadowColor:_infoMationView];
    
    [self.contentView addSubview:_infoMationView];
    
    _image = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, _infoMationView.width / 5, _infoMationView.height)];
    [UIView viewRediusForTopAndBottomForLeft:_image withRedius:4];
    _image.backgroundColor = kRandomColor;
    [_infoMationView addSubview:_image];
    
    _labelImageCN = [[UILabel alloc] initWithFrame:CGRectMake(2, _image.height - 15, _image.width - 3, 8)];
    _labelImageCN.font = [UIFont boldSystemFontOfSize:9];
//    _labelImageCN.text = @"中央美术学院";
    _labelImageCN.textColor = [UIColor whiteColor];
    [_image addSubview:_labelImageCN];
    
    _labelImageEN = [[UILabel alloc] initWithFrame:CGRectMake(2, _infoMationView.height - _labelImageCN.height - 20, _image.width - 3, 8)];
    _labelImageEN.font = [UIFont systemFontOfSize:8];
    _labelImageEN.text = @"Beijing";
    _labelImageEN.textColor = [UIColor whiteColor];
//    [_image addSubview:_labelImageEN];
    
    _labelDate = [[UILabel alloc] initWithFrame:CGRectMake(_image.width + 5, _image.height - 30, _image.width * 4 - 35, 30)];
//    _labelDate.text = @"2015年9月12日";
    _labelDate.font = [UIFont systemFontOfSize:12];
    _labelDate.textColor = kCustomColor(150, 150, 150, 1);
    [_infoMationView addSubview:_labelDate];
    
    _labelInfo = [[UILabel alloc] initWithFrame:CGRectMake(_image.width + 5, -10, _image.width * 4 - 60, 60)];
//    _labelInfo.text = @"中央美术学院建筑学院发布新的招生方案，旨在让更多的学生可以更好的...";
    _labelInfo.font = [UIFont systemFontOfSize:12];
    _labelInfo.numberOfLines = 2;
    _labelInfo.textColor = kCustomColor(50, 50, 70, 1);

    [_infoMationView addSubview:_labelInfo];
}

- (void)setModel:(InfoMactionModel *)model
{
    _model = model;
//    [_image sd_setImageWithURL:[NSURL URLWithString:_model.feedContent[@"headImg"]] placeholderImage:nil options:SDWebImageRetryFailed | SDWebImageLowPriority];
    
    [_image sd_setImageWithURL:[NSURL URLWithString:_model.feedContent[@"headImg"]]  placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageLowPriority) completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        UIImage *bImage = [image boxblurImageWithBlur:0.75];
        _image.image = bImage;
        
    }];
    
    
    _labelImageCN.text = _model.feedContent[@"spaceName"];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:[_model.feedContent[@"addTime"] intValue] - 86400];
    //格式化时间
    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    //设置格式
    [formater setDateFormat:@"MM月dd日 HH:mm"];
    //获取系统的时间区域
    formater.timeZone = [NSTimeZone systemTimeZone];
    //设定本地化，时间会按照本地的习惯和文字显示日期
    formater.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-us"];
    NSString *string = [formater stringFromDate:date];
    
    _labelDate.text = string;
    _labelInfo.text = _model.feedContent[@"intro"];
    _labelImageEN.text = _model.feedContent[@"title"];
}

@end
